package cn.zhizihua.service.impl;

import cn.zhizihua.domain.po.User;
import cn.zhizihua.domain.vo.ResultBean;
import cn.zhizihua.mapper.UserMapper;
import cn.zhizihua.service.IUserService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;


@Service
public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements IUserService {

    @Autowired
    UserMapper userMapper;


    //TODO APPController
    @Override
    public ResultBean login(String userName, String password) {
        if (userName==null || "".equals(userName) ||
                password==null || "".equals(password)){
            return ResultBean.ERROR("请求参数为空值");
        }

        //通过用户名查询用户是否存在
        User user = userMapper.getByUserName(userName);

        if (user==null){
            return ResultBean.ERROR("用户不存在");
        }

        if(!user.getPassword().equals(password)){
            return ResultBean.ERROR("密码错误");
        }

        //密码不给到前端
        user.setPassword(null);

        return ResultBean.SUCCESS(user);
    }


}
